/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.algorithmConfig.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.biz.modular.algorithmConfig.param.*;
import vip.xiaonuo.biz.modular.config.param.PushConfigureParam;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.biz.modular.algorithmConfig.entity.AlgorithmConfig;
import vip.xiaonuo.biz.modular.algorithmConfig.service.AlgorithmConfigService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import vip.xiaonuo.common.util.CommonHttp;

import java.io.IOException;
import java.util.List;

/**
 * 算法配置控制器
 *
 * @author mengxiaowei
 * @date  2024/09/12 14:47
 */
@Tag(name = "算法配置控制器")
@RestController
@Validated
public class AlgorithmConfigController {

    @Resource
    private AlgorithmConfigService algorithmConfigService;

    /**
     * 获取算法配置分页
     *
     * @author mengxiaowei
     * @date  2024/09/12 14:47
     */
    @Operation(summary = "获取算法配置分页")
    //@SaCheckPermission("/biz/algorithmConfig/page")
    @GetMapping("/biz/algorithmConfig/page")
    public CommonResult<Page<AlgorithmConfig>> page(AlgorithmConfigPageParam algorithmConfigPageParam) {
        return CommonResult.data(algorithmConfigService.page(algorithmConfigPageParam));
    }

    /**
     * 添加算法配置
     *
     * @author mengxiaowei
     * @date  2024/09/12 14:47
     */
    @Operation(summary = "添加算法配置")
    @CommonLog("添加算法配置")
    @SaCheckPermission("/biz/algorithmConfig/add")
    @PostMapping("/biz/algorithmConfig/add")
    public CommonResult<String> add(@RequestBody @Valid AlgorithmConfigAddParam algorithmConfigAddParam) {
        algorithmConfigService.add(algorithmConfigAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑算法配置
     *
     * @author mengxiaowei
     * @date  2024/09/12 14:47
     */
    @Operation(summary = "编辑算法配置")
    @CommonLog("编辑算法配置")
    @SaCheckPermission("/biz/algorithmConfig/edit")
    @PostMapping("/biz/algorithmConfig/edit")
    public CommonResult<String> edit(@RequestBody @Valid AlgorithmConfigEditParam algorithmConfigEditParam) {
        algorithmConfigService.edit(algorithmConfigEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除算法配置
     *
     * @author mengxiaowei
     * @date  2024/09/12 14:47
     */
    @Operation(summary = "删除算法配置")
    @CommonLog("删除算法配置")
    @SaCheckPermission("/biz/algorithmConfig/delete")
    @PostMapping("/biz/algorithmConfig/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<AlgorithmConfigIdParam> algorithmConfigIdParamList) {
        algorithmConfigService.delete(algorithmConfigIdParamList);
        return CommonResult.ok();
    }



    @Operation(summary = "获取算法配置详情")
    //@SaCheckPermission("/biz/algorithmConfig/queryAlgo")
    @GetMapping("/biz/algorithmConfig/queryAlgo")
    public CommonResult<List<AlgorithmConfig>> queryAlgo(String id) {
        return CommonResult.data(algorithmConfigService.queryAlgo(id));
    }







    /**
     * 获取算法配置详情
     *
     * @author mengxiaowei
     * @date  2024/09/12 14:47
     */
    @Operation(summary = "通过deviceId查询算法")
    //@SaCheckPermission("/biz/algorithmConfig/getAlgorithmByDeviceId")
    @GetMapping("/biz/algorithmConfig/getAlgorithmByDeviceId")
    public CommonResult<List<AlgorithmConfig>> getAlgorithmByDeviceId(String id) {
        return CommonResult.data(algorithmConfigService.queryAlgorithm(id));
    }

    /**
     * 添加算法配置
     *
     * @author mengxiaowei
     * @date  2024/09/12 14:47
     */
    @Operation(summary = "接收睡眠报告")
    @CommonLog("接收睡眠报告")
    @PostMapping("/biz/algorithmConfig/receiveSleepReport")
    public CommonResult<String> receiveSleepReport(@RequestBody ReceiveSleepReportParam receiveSleepReportParam) throws IOException {
        algorithmConfigService.receiveSleepReport(receiveSleepReportParam);
        return CommonResult.ok();
    }

    @Operation(summary = "上传文件")
    @CommonLog("上传文件")
    @PostMapping("/biz/algorithmConfig/upload")
    public CommonResult<String> upload(@RequestParam("file") MultipartFile file) throws IOException {
        CommonHttp.httpFile(file.getName(),"https://dev.uidti.com/cgi-bin/application/service/resource/oss/upload");
        return CommonResult.ok();
    }







}
